﻿
Imports GalaSoft.MvvmLight
Imports GalaSoft.MvvmLight.Command

Namespace FL_8x0.Viewmodel

    Public Class ExitViewModel : Inherits ViewModelBase

        Private _logoutCommand As RelayCommand(Of Window)   '点击“注销”触发命令

        Private _closeCommand As RelayCommand(Of Window)    '点击“关闭”触发命令


        Public Sub New()
            LogoutCommand = New RelayCommand(Of Window)(Sub(w) Logout(w))
            CloseCommand = New RelayCommand(Of Window)(Sub(w) Close(w))

        End Sub

        '=====================================================================
        '函 数 名: Close
        '参    数: 
        '返 回 值:
        '功能描述: 关闭窗口
        '=====================================================================
        Private Sub Close(window As Window)
            window.Close()
        End Sub

        '=====================================================================
        '函 数 名: Logout
        '参    数: 
        '返 回 值:
        '功能描述: 注销
        '=====================================================================
        Private Sub Logout(window As Window)
            Application.Current.Shutdown()
            Task.Run(Sub() Restart())
            'window.Hide()
            'MainWindow.LogOut()
        End Sub

        '=====================================================================
        '函 数 名: Restart
        '参    数: 
        '返 回 值:
        '功能描述: 重新启动
        '=====================================================================
        Private Sub Restart()
            Dim path As String = AppDomain.CurrentDomain.BaseDirectory & "Wpf.fl-830.exe"
            Process.Start(path)
        End Sub


        Public Property LogoutCommand As RelayCommand(Of Window)
            Get
                Return _logoutCommand
            End Get
            Set
                _logoutCommand = Value
            End Set
        End Property


        Public Property CloseCommand As RelayCommand(Of Window)
            Get
                Return _closeCommand
            End Get
            Set
                _closeCommand = Value
            End Set
        End Property

    End Class
End Namespace